﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPMS.Commons.Configuration;

namespace SPMS.Log.Configuration.Handler
{
    /// <summary>
    /// 日志记录器组节点解析器
    /// </summary>
    /// <remarks>用于解析日志记录器节点</remarks>
    /// <history>
    /// [zanezeng]               2009/10/15 14:43    创建
    /// </history>
    public sealed class Loggers_NodeHandler : AbstractNodeHandler
    {
        /// <summary>
        /// 处理指定的节点
        /// </summary>
        /// <param name="node">配置节点</param>
        /// <param name="context">处理上下文</param>
        /// <returns>根据配置信息创建的对象</returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   2008-11-17 11:39    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/15 14:43    创建
        /// </history>
        protected override object ProcessInternal( IConfigurationNode node, ParseContext context )
        {
            //用于保存结果
            List<object> instances = new List<object>();

            //用于保存对象实例
            object instance = null;

            //用于保存配置节点处理器
            IConfigurationNodeHandler<ParseContext> handler;

            //循环当前配置节点的所有子节点
            foreach (IConfigurationNode subNode in node.ChildNodes)
            {
                //获得配置节点处理器
                handler = context.GetNodeHandler( subNode );

                //判断是否为Null
                if (null == handler)
                {
                    //抛出异常
                    throw new NotSupportedException( string.Format( Properties.Resources.MSG_TAG_NOTSUPPORTED, subNode.Name ) );
                }

                //处理节点
                instance = handler.Porcess( subNode, context );

                //添加到列表
                instances.Add( instance );
            }

            //返回所有的子节点
            return instances;
        }
    }
}
